home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / testers.rep / code.ys < prev   
Encoding:
Text File  |  2002-03-13  |  2.9 KB  |  185 lines

  1.  
  2. /* Functions that aid in testing */
  3.  
  4. /* Round to specified number of digits */
  5. RoundTo(x_IsNumber, prec_IsPositiveInteger) <-- N(Round(x*10^prec)*10^(-prec));
  6.  
  7. /* Logging functions */
  8. // curline:=0;
  9.  
  10. /*
  11. Function("StartTests",{})
  12. [
  13.   curline:=0;
  14. ];
  15. */
  16. /*
  17. Function("NextTest",{aLeft})
  18. [
  19. // curline++;
  20. WriteString("
  21. Test suite for ":aLeft:" : "
  22.            );
  23.   NewLine();
  24. ];
  25. */
  26. /*
  27. Function("Testing",{aLeft})
  28. [
  29.  WriteString(aLeft); NewLine();
  30. ];
  31. */
  32.  
  33. Function("KnownFailure",{expr})
  34. [
  35.   Local(rfail);
  36.   Echo({"Known failure:"});
  37.   Set(rfail,Eval(expr));
  38.   If(rfail,Echo({"Failure resolved!"}));
  39. ];
  40. HoldArg("KnownFailure",expr);
  41.  
  42. Function("Verify",{aLeft,aRight})
  43. [
  44.   If (Not(Equals(Eval(aLeft),aRight)),
  45.     [
  46.       WriteString("******************");
  47.       NewLine();
  48.       Write(aLeft);
  49.       WriteString(" evaluates to ");
  50.       Write(Eval(aLeft));
  51.       WriteString(" which differs from ");
  52.       Write(aRight);
  53.       NewLine();
  54.       WriteString("******************");
  55.       NewLine();
  56.       False;
  57.     ],
  58.     True
  59.   );
  60. ];
  61. /*
  62. HoldArg("Verify",aLeft);
  63. HoldArg("Verify",aRight);
  64. */
  65.  
  66. Function("LogicVerify",{aLeft,aRight})
  67. [
  68.   If(aLeft != aRight,
  69.     Verify(CanProve(aLeft => aRight),True)
  70.   );
  71. ];
  72.  
  73.  
  74. f1(x,n,m):=(x^n-1)*(x^m-1);
  75. f2(x,n,m):=x^(n+m)-(x^n)-(x^m)+1;
  76.  
  77. VerifyArithmetic(x,n,m):=
  78. [
  79. /*
  80.   WriteString("Checking arithmetic with ");
  81.   Write(x);Space();
  82.   Write(n);Space();
  83.   Write(m);NewLine();
  84. */
  85.   Verify(f1(x,n,m),f2(x,n,m));
  86. ];
  87. RandVerifyArithmetic(_n)<--
  88. [
  89.  While(n>0)
  90.  [
  91.    n--;
  92.    VerifyArithmetic(MathFloor(300*Random()),MathFloor(80*Random()),MathFloor(90*Random()));
  93.  ];
  94. ];
  95.  
  96. VerifyDiv(_u,_v) <--
  97. [
  98.   Local(q,r);
  99.   q:=Div(u,v);
  100.   r:=Rem(u,v);
  101.  
  102.   Verify(Expand(u),Expand(q*v+r));
  103. ];
  104.  
  105. 10 # EchoInternal(string_IsString) <--
  106. [
  107.   WriteString(string);
  108. ];
  109.  
  110. 20 # EchoInternal(_item) <--
  111. [
  112.   Write(item);Space();
  113. ];
  114.  
  115. 10 # Echo(list_IsList)<--
  116. [
  117.   ForEach(item,list) EchoInternal(item);
  118.   NewLine();
  119. ];
  120. 20 # Echo(_item)<--
  121. [
  122.   EchoInternal(item);
  123.   NewLine();
  124. ];
  125.  
  126.  
  127. Function("BenchCall",{expr}) 
  128. [
  129.   Echo({"In> ",expr});
  130.   WriteString("<font color=ff0000>");
  131.   Eval(expr);
  132.   WriteString("</font>");
  133.   True;
  134. ];
  135. HoldArg("BenchCall",expr);
  136.  
  137. Function("BenchShow",{expr}) 
  138. [
  139.   Echo({"In> ",expr});
  140.   WriteString("<font color=ff0000> ");
  141.   Echo({"Out> ",Eval(expr),"</font>"});
  142.   True;
  143. ];
  144. HoldArg("BenchShow",expr);
  145.  
  146.  
  147.  
  148.  
  149. /* Testing Yacas functionality by checking expressions against correct
  150.    answer.
  151.    Use with algebraic expressions only, since we need Simplify() for that to work.
  152.  */
  153.  
  154. Function ("TestYacas", {expr, ans})
  155. [
  156.         If (Simplify(Eval(expr)-ans)=0, True,
  157.             [
  158.               WriteString("******************");
  159.               NewLine();
  160.               Write(Hold(expr));
  161.               WriteString(" evaluates to ");
  162.               NewLine();
  163.               Write(Eval(expr));
  164.               NewLine();
  165.               WriteString(" which differs from ");
  166.               NewLine();
  167.               Write(ans);
  168.               NewLine();
  169.               WriteString("******************");
  170.               NewLine();
  171.               False;
  172.              ]
  173.             );
  174. ];
  175.  
  176. HoldArg("TestYacas", expr);
  177. HoldArg("TestYacas", ans);
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.